import * as vscode from 'vscode';
import {dedent} from "../../../utils";

// documentation中使用了代码块，代码块中写的事makedown格式，首行不能为空
let particleEffectItems = [
    {
        "label": "ParticleEffect_Create",
        "insertText": dedent`
        local particle = GUI:ParticleEffect_Create(\${1:parent}, \${2:"ParticleEffect_1"}, \${3:200}, \${4:200}, \${5:"res/private/particles/petal_1.plist"})
        `,
        "documentation": dedent`# 创建粒子特效
        ## ParticleEffect_Create(parent, ID, x, y, res)

        | 参数   | 必选 | 类型   | 注释                       |
        | :----- | :--- | :----- | :------------------------- |
        | parent | 是   | obj    | 父节点对象                 |
        | ID     | 是   | string | 唯一ID                     |
        | x      | 是   | int    | 位置 横坐标                |
        | y      | 是   | int    | 位置 纵坐标                |
        | res    | 是   | string | 粒子特效资源路径 plist文件 |
        `
    },
    {
        "label": "ParticleEffect_setDuration",
        "insertText": dedent`
        GUI:ParticleEffect_setDuration(\${1:widget}, \${2:-1})
        `,
        "documentation": dedent`# 设置持续时间
        ## ParticleEffect_setDuration(widget, value)

        | 参数   | 必选 | 类型 | 注释                           |
        | :----- | :--- | :--- | :----------------------------- |
        | widget | 是   | obj  | 粒子特效                       |
        | value  | 是   | int  | 持续时间, 单位: 秒 -1 表示永久 |
        `
    },
    {
        "label": "ParticleEffect_setTotalParticles",
        "insertText": dedent`
        GUI:ParticleEffect_setTotalParticles(\${1:widget}, \${2:999})
        `,
        "documentation": dedent`# 设置总粒子数量
        ## ParticleEffect_setTotalParticles(widget, value)

        | 参数   | 必选 | 类型 | 注释     |
        | :----- | :--- | :--- | :------- |
        | widget | 是   | obj  | 粒子特效 |
        | value  | 是   | int  | 数量     |

        - 示例代码
        \`\`\`
        local widget = GUI:ParticleEffect_Create(GUI:Attach_LeftBottom(), "TT", 568, 320, "res/private/particles/petal_1.plist")
        GUI:ParticleEffect_setDuration(widget, -1)
        GUI:ParticleEffect_setTotalParticles(widget, 999)
        \`\`\`
        `
    }
]



export function getCompletionItems(): vscode.CompletionItem[] {


    const completionItems: vscode.CompletionItem[] = [];
    particleEffectItems.forEach((item: any) => {
        completionItems.push(createFunctionCompletionItem(item.label, item.insertText, item.documentation));
    });
    return completionItems;
}

function createFunctionCompletionItem(label: string, insertText: string, documentation?: string): vscode.CompletionItem {
    const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
    item.insertText = new vscode.SnippetString(insertText);
    if (documentation) {
        item.documentation = new vscode.MarkdownString(documentation);
    }
    return item;
}
